#pragma once
#include <stddef.h>
#include "../../components/math/Vecnt.h"
#include "../../components/math/Matnnt.h"
/************************************************************************/
/*                Common defines                                        */
/************************************************************************/
// the maximum time for one frame is 1000/20 = 50 ms, which means  the lowest FPS is 20.
#define MAX_FRAME_TIME 50 

typedef unsigned char BYTE;
typedef nvmath::Vecnt<4, float> KVec4;
typedef nvmath::Vecnt<3, float> KVec3;
typedef nvmath::Vecnt<2, float> KVec2;
typedef nvmath::Vecnt<2, int>	KVecInt2;
typedef nvmath::Quatf KQuat;
typedef nvmath::Mat44f KMatrix4;

class KRotation
{
public:
	KRotation();
	KRotation(float degree);

	void SetRadian(float radian);
	void SetDegree(float degree);

public:
	float mSinTheta;
	float mCosTheta;
};

class KRect
{
public:
	KVec2 left_bottom;
	KVec2 right_top;

	KVec2 GetCenter() const {return (left_bottom + right_top) * 0.5f;}
	bool IsInside(const KVec2& pt) {return (pt[0] >= left_bottom[0] && pt[0] < right_top[0] && pt[1] >= left_bottom[1] && pt[1] < right_top[1]);}
};

typedef unsigned int KColor;  // order is RGBA(from low to high byte)
/************************************************************************/
/*                 Windows platform                                     */
/************************************************************************/
#ifdef WIN_BUILD
	struct VERTEX_P
	{
		float pos[3];
	};

	struct VERTEX_PC
	{
		float pos[3];
		unsigned int color;
	};

	struct VERTEX_PT
	{
		float pos[3];
		float uv[2];
	};
#define MAKE_RGBA(r, g, b, a) ((a<<24) | (r<<16) | (g<<8) | b)
#endif

/************************************************************************/
/*                   PSP platform                                       */
/************************************************************************/
#ifdef PSP_BUILD	
	struct VERTEX_P
	{
		float pos[3];
	};

	struct VERTEX_PC
	{
		unsigned int color;
		float pos[3];
	};

	struct VERTEX_PT
	{
		float uv[2];
		float pos[3];
	};
#define MAKE_RGBA(r, g, b, a) ((a<<24) | (b<<16) | (g<<8) | r)
#endif

/************************************************************************/
/*                   Android platform                                   */
/************************************************************************/
#ifdef ANDROID_BUILD
	struct VERTEX_P
	{
		float pos[3];
	};

	struct VERTEX_PC
	{
		float pos[3];
		unsigned int color;
	};

	struct VERTEX_PT
	{
		float pos[3];
		float uv[2];
	};
#define MAKE_RGBA(r, g, b, a) ((a<<24) | (b<<16) | (g<<8) | r)
#endif

#define SET_VERTEX_POS(v, x, y) {v.pos[0] = x; v.pos[1] = y; v.pos[2] = 0;}


int NextPowerOfTwo(int a);